package com.guohong.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.guohong.common.RestResult;
import com.guohong.constant.ResponseCodeConstant;
import com.guohong.dto.OrderPageDto;
import com.guohong.exception.ServiceException;
import com.guohong.service.OrderService;
import com.guohong.vo.OrderQueryVo;

@RestController
@RequestMapping("/order")
public class OrderController {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	// @Autowired
	// private MaodouUserService maodouUserService;

	@Autowired
	private OrderService orderService;

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public RestResult<OrderPageDto> list(@RequestBody OrderQueryVo orderQueryVo) {
		logger.info(orderQueryVo.toString());

		RestResult<OrderPageDto> result = new RestResult<>();

		try {
			OrderPageDto orderPageDto = orderService.listOrdersByPage(orderQueryVo.getOrderNo(), orderQueryVo.getPageNum(),
					orderQueryVo.getPageSize());

			result.setCode(ResponseCodeConstant.SUCCESS);
			result.setData(orderPageDto);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setCode(e.getCode());
			result.setMsg(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			result.setCode(ResponseCodeConstant.FAILED);
			result.setMsg("系统内部错误");
		}

		return result;
	}

}
